<%@page contentType="text/html; charset=utf-8"%>
<%@ include file="../inc/TagLibs.jsp"%>
<c:set var="pageTitle" value="业务单审核" />
<%@ include file="../inc/Title.jsp"%>
<head>
<link rel="stylesheet" type="text/css" href="/css/base.css" />
<script src="/js/popup_ext.js"></script>
<script language="javascript">
	function doCancel(){
		parent.ClosePop();
	}
	function doExamine(id){
		var errMsg="";
		var bbItemNum=${fn:length(record.items)};
		var i;
		var wcIdStr="";
		var cooperStr="";
		
		for(i=0;i<bbItemNum;i++){
			var bbItemId=document.getElementById("cooper_cb_"+i).value;
			if(document.getElementById("cooper_cb_"+i).checked){
				cooperStr=cooperStr+";"+bbItemId+";";
			}
			if(wcIdStr!=""){
				wcIdStr=wcIdStr+";";
			}
			//if(!document.getElementById("cooper_cb_"+i).checked && (document.getElementById("wc_id_"+i).value=="" || document.getElementById("wc_id_"+i).value=="0")){
			//	errMsg="请选择自制的工作中心，或者标记为外协";
			//}
			wcIdStr=wcIdStr+bbItemId+":"+document.getElementById("wc_id_"+i).value;
		}
		document.getElementById("cooper_str").value=cooperStr;
		document.getElementById("wc_id_str").value=wcIdStr;
		
		var accWcIdStr="";
		var accTypeStr="";
		var accItemNum=${fn:length(record.accessories)};
		for(i=0;i<accItemNum;i++){
			var accItemId=document.getElementById("acc_id_"+i).value;
			if(accWcIdStr!=""){
				accWcIdStr=accWcIdStr+";";
			}
			accWcIdStr=accWcIdStr+accItemId+":"+document.getElementById("acc_wc_id_"+i).value;
			if(accTypeStr!=""){
				accTypeStr=accTypeStr+";";
			}
			accTypeStr=accTypeStr+accItemId+":"+document.getElementById("acc_type_"+i).value;
			
			var accWcId=document.getElementById("acc_wc_id_"+i).value;
			if(document.getElementById("acc_type_"+i).value=="DESIGN" && (accWcId=="" || accWcId=="0")){
				errMsg="请选择附件的工作中心";
			}
		}
		
		if(errMsg==""){
			ShowConfirm('确认框','确定审核通过吗？',340,80,"doExamineCallBack('"+accWcIdStr+"','"+accTypeStr+"')");
		}else{
			ShowAlert('提示框',errMsg,200,100);
		}
	}
	function doExamineCallBack(accWcIdStr,accTypeStr){
		if(popRetVal!=null){
			document.getElementById("acc_wc_id_str").value=accWcIdStr;
			document.getElementById("acc_type_str").value=accTypeStr;
			frm.submit();
		}
	}
	function doDownload(id,fileName,sourceName){
		var xmlHttp=createXMLHttpRequest();
		xmlHttp.open("GET", "/FileDownloadLog.ihtm?id="+id);
		xmlHttp.onreadystatechange = function(){
			doDownloadCallback(xmlHttp,fileName,sourceName);
		};
		xmlHttp.send(null);
	}
	function doDownloadCallback(xmlHttp,fileName,sourceName){
    	if (xmlHttp.readyState == 4) {
      		if (xmlHttp.status == 200) {
      			var resTxt=xmlHttp.responseText;
      			if(resTxt=="NO_LOGIN"){
      				ShowAlert('提示框','你还没登录或已经超时，请重新登录。',200,100);
      			}else if(resTxt=="OK"){
      				window.location="/FileDownload.ihtm?file_name="+encodeURIComponent(fileName)+"&source_name="+encodeURIComponent(sourceName);
      			}
			}
		}
	}
	function doEdit(id){
		var url="/business/BusinessBillEdit.ihtm?id="+id;
		ShowIframe("业务单",url,1024,600,"refreshWin()",1024,500);
	}
	function refreshWin(){
		window.location=window.location;
	}
	function doNewMessage(billId,billCode,receiverId,receiverName){
		var defaultUrl="/message/MessageNew.ihtm?relation_id="+billId+"&receiver_id="+receiverId+"&receiver_name="+encodeURIComponent(receiverName)+"&title="+encodeURIComponent(billCode+"已被退回修改")+"&content="+encodeURIComponent(billCode);
		var url="/message/Main.ihtm?default_url="+encodeURIComponent(defaultUrl);
		showWin(1024,600,url);
	}
	
	function doClear(idObjId,nameObjId){
		if(idObjId!=null && idObjId!=''){
			document.getElementById(idObjId).value="0";
		}
		if(nameObjId!=null && nameObjId!=''){
			document.getElementById(nameObjId).value="";
		}
	}
	function selectWc(idObjId,nameObjId){
		var url="/base/WorkCenterListForSelect.ihtm";
		ShowIframe("选择工作中心",url,600,400,"selectWcCallBack('"+idObjId+"','"+nameObjId+"')");
	}
	function selectWcCallBack(idObjId,nameObjId){
		if(popRetVal!=null){
			document.getElementById(idObjId).value=popRetVal[0];
			document.getElementById(nameObjId).value=popRetVal[1];
		}
	}
	function doInit(){
	}
</script>
</head>
<body oncontextmenu="return false" onload="doInit();" class="sheet modal-dialog" style=" padding-top:10px;text-align:center;">
<div class="sheet-main" id="bodyDiv" style="width:980px;text-align:left;">
  <div class="sheet-list" style="width:100%">
    <div class="modal-main search-business">
		<div style="width:100%;">
	 			<table border="0" cellspacing="0" cellpadding="0" align="center" class="table-0">
	 				<tr>
	 					<td style="width:33%" rowspan="2"></td>
	 					<td style="width:33%;text-align:center" rowspan="2"><h2>业务单审核</h2></td>
	 					<td style="width:34%" class="tr">
	 						编号：${record.businessBill.billCode}
	 					</td>
	 				</tr>
	 				<tr>
	 					<td class="tr">订货日期：<fmt:formatDate value="${record.businessBill.orderDate}" pattern="yyyy-MM-dd HH:mm"/></td>
	 				</tr>
	 			</table>
	 			
	 			<table border="0" cellspacing="0" cellpadding="0" align="center" class="table-0">
				    <tr>
	 					<td class="InfoTitleDivider"></td>
	 				</tr>
				</table>
	 			
				<table border="0" cellspacing="0" cellpadding="0" align="center" class="table-0">
					<tr>
				      	<th style="width:6%">客户：</th>
				      	<td style="width:26%">${record.clientName}<span class="lbClientNote">${record.clientLevel}</span></td>
				      	<th style="width:8%">联系人：</th>
				     	<td style="width:16%">${record.businessBill.linkman}</td>
				     	<th style="width:6%">电话：</th>
				     	<td style="width:16%">${record.businessBill.phone}
				    	<td class="tr" style="width:22%">合同号：${record.businessBill.contractCode}</td>
				    </tr>
				</table>
				
				<table border="0" cellspacing="0" cellpadding="0" align="center" class="table-0">
				    <tr>
	 					<td class="InfoTitleDivider"></td>
	 				</tr>
				</table>
				
				<div class="table-list">
					<c:set var="hasPreTbl" value="N" />
					<c:if test="${record.hasAreaItem=='Y'}">
					<c:if test="${hasPreTbl=='Y'}"><br></c:if>
					<c:set var="hasPreTbl" value="Y" />
					<table width="98%" border="0" cellspacing="0" cellpadding="0" align="center">
						<tbody>
						<tr >
							<th width="10%" >项目类型</th>
							<th width="12%" >内容</th>
							<th width="12%" >材质</th>
							<th width="12%" >规格</th>
							<th width="12%" >制作要求</th>
							<th width="6%" >数量</th>
							<th width="6%" >平方数</th>
							<th width="6%" >单价</th>
							<th width="7%" >金额</th>
							<th width="4%" >外协</th>
							<th width="4%" >安装</th>
							<th width="9%" >工作中心</th>
						</tr>
						<c:forEach var="item" items="${record.items}" varStatus="i">
						<c:if test="${item.businessBillItem.priceType=='AREA'}">
						<tr >
							<td>${item.makeTypeName}</td>
							<td><commonTag:parseEnterToBr source="${item.businessBillItem.finishedContent}" /></td>
							<td>${item.businessBillItem.proName}</td>
							<td><commonTag:parseEnterToBr source="${item.businessBillItem.specification}" /></td>
							<td><commonTag:parseEnterToBr source="${item.businessBillItem.makeRequire}" /></td>
							<td><commonTag:parseBigDecimal source="${item.businessBillItem.amount}" /></td>
							<td><commonTag:parseBigDecimal source="${item.businessBillItem.squareNum}" /></td>
							<td><commonTag:parseBigDecimal source="${item.businessBillItem.unitPrice}" /></td>
							<td><commonTag:parseBigDecimal source="${item.businessBillItem.cost}" /></td>
							<td><input type="checkbox" name='cooper_cb_${i.index}' id='cooper_cb_${i.index}' value="${item.businessBillItem.id}" <c:if test="${item.businessBillItem.isCoop=='Y'}">checked="true"</c:if>></td>
							<td><c:if test="${item.businessBillItem.isSetu=='Y'}">是</c:if></td>
							<td>
								<input class='TextBox readonly' readonly="true" type="text" style="width:68px" id="wc_name_${i.index}" name="wc_name_${i.index}" value='<commonTag:showSimpleObjectName list="${workCenterList}" objectId="${item.businessBillItem.wcId}" />'>
								<img src="/images/icon_add.gif" style="cursor:pointer;" onClick="selectWc('wc_id_${i.index}','wc_name_${i.index}');">
								<img src="/images/icon_del.gif" style="cursor:pointer;" onClick="doClear('wc_id_${i.index}','wc_name_${i.index}');">
								<input type="hidden" id="wc_id_${i.index}" name="wc_id_${i.index}" value="${item.businessBillItem.wcId}">
							</td>
						</tr>
						</c:if>
						</c:forEach>
						</tbody>
				  </table>
				  </c:if>
				  
				  <c:if test="${record.hasLengthItem=='Y'}">
					<c:if test="${hasPreTbl=='Y'}"><br></c:if>
					<c:set var="hasPreTbl" value="Y" />
					<table width="98%" border="0" cellspacing="0" cellpadding="0" align="center">
						<tbody>
						<tr >
							<th width="10%" >项目类型</th>
							<th width="12%" >内容</th>
							<th width="12%" >材质</th>
							<th width="12%" >规格</th>
							<th width="12%" >制作要求</th>
							<th width="6%" >数量</th>
							<th width="6%" >总长度</th>
							<th width="6%" >单价</th>
							<th width="7%" >金额</th>
							<th width="4%" >外协</th>
							<th width="4%" >安装</th>
							<th width="9%" >工作中心</th>
						</tr>
						<c:forEach var="item" items="${record.items}" varStatus="i">
						<c:if test="${item.businessBillItem.priceType=='LENGTH'}">
						<tr >
							<td>${item.makeTypeName}</td>
							<td><commonTag:parseEnterToBr source="${item.businessBillItem.finishedContent}" /></td>
							<td>${item.businessBillItem.proName}</td>
							<td><commonTag:parseEnterToBr source="${item.businessBillItem.specification}" /></td>
							<td><commonTag:parseEnterToBr source="${item.businessBillItem.makeRequire}" /></td>
							<td><commonTag:parseBigDecimal source="${item.businessBillItem.amount}" /></td>
							<td>
								<commonTag:parseBigDecimal source="${item.businessBillItem.squareNum}" />
								<c:if test="${item.businessBillItem.lengType=='M'}">米</c:if><c:if test="${item.businessBillItem.lengType=='CM'}">公分</c:if>
							</td>
							<td><commonTag:parseBigDecimal source="${item.businessBillItem.unitPrice}" /></td>
							<td><commonTag:parseBigDecimal source="${item.businessBillItem.cost}" /></td>
							<td><input type="checkbox" name='cooper_cb_${i.index}' id='cooper_cb_${i.index}' value="${item.businessBillItem.id}" <c:if test="${item.businessBillItem.isCoop=='Y'}">checked="true"</c:if>></td>
							<td><c:if test="${item.businessBillItem.isSetu=='Y'}">是</c:if></td>
							<td>
								<input class='TextBox readonly' readonly="true" type="text" style="width:68px" id="wc_name_${i.index}" name="wc_name_${i.index}" value='<commonTag:showSimpleObjectName list="${workCenterList}" objectId="${item.businessBillItem.wcId}" />'>
								<img src="/images/icon_add.gif" style="cursor:pointer;" onClick="selectWc('wc_id_${i.index}','wc_name_${i.index}');">
								<img src="/images/icon_del.gif" style="cursor:pointer;" onClick="doClear('wc_id_${i.index}','wc_name_${i.index}');">
								<input type="hidden" id="wc_id_${i.index}" name="wc_id_${i.index}" value="${item.businessBillItem.wcId}">
							</td>
						</tr>
						</c:if>
						</c:forEach>
						</tbody>
				  </table>
				  </c:if>
				  
				  <c:if test="${record.hasAmountItem=='Y'}">
					<c:if test="${hasPreTbl=='Y'}"><br></c:if>
					<c:set var="hasPreTbl" value="Y" />
					<table width="98%" border="0" cellspacing="0" cellpadding="0" align="center">
						<tbody>
						<tr >
							<th width="10%" >项目类型</th>
							<th width="12%" >内容</th>
							<th width="12%" >材质</th>
							<th width="12%" >规格</th>
							<th width="12%" >制作要求</th>
							<th width="6%" >单位</th>
							<th width="6%" >数量</th>
							<th width="6%" >单价</th>
							<th width="7%" >金额</th>
							<th width="4%" >外协</th>
							<th width="4%" >安装</th>
							<th width="9%" >工作中心</th>
						</tr>
						<c:forEach var="item" items="${record.items}" varStatus="i">
						<c:if test="${item.businessBillItem.priceType=='AMOUNT'}">
						<tr >
							<td>${item.makeTypeName}</td>
							<td><commonTag:parseEnterToBr source="${item.businessBillItem.finishedContent}" /></td>
							<td>${item.businessBillItem.proName}</td>
							<td><commonTag:parseEnterToBr source="${item.businessBillItem.specification}" /></td>
							<td><commonTag:parseEnterToBr source="${item.businessBillItem.makeRequire}" /></td>
							<td>${item.businessBillItem.unit}</td>
							<td><commonTag:parseBigDecimal source="${item.businessBillItem.amount}" /></td>
							<td><commonTag:parseBigDecimal source="${item.businessBillItem.unitPrice}" /></td>
							<td><commonTag:parseBigDecimal source="${item.businessBillItem.cost}" /></td>
							<td><input type="checkbox" name='cooper_cb_${i.index}' id='cooper_cb_${i.index}' value="${item.businessBillItem.id}" <c:if test="${item.businessBillItem.isCoop=='Y'}">checked="true"</c:if>></td>
							<td><c:if test="${item.businessBillItem.isSetu=='Y'}">是</c:if></td>
							<td>
								<input class='TextBox readonly' readonly="true" type="text" style="width:68px" id="wc_name_${i.index}" name="wc_name_${i.index}" value='<commonTag:showSimpleObjectName list="${workCenterList}" objectId="${item.businessBillItem.wcId}" />'>
								<img src="/images/icon_add.gif" style="cursor:pointer;" onClick="selectWc('wc_id_${i.index}','wc_name_${i.index}');">
								<img src="/images/icon_del.gif" style="cursor:pointer;" onClick="doClear('wc_id_${i.index}','wc_name_${i.index}');">
								<input type="hidden" id="wc_id_${i.index}" name="wc_id_${i.index}" value="${item.businessBillItem.wcId}">
							</td>
						</tr>
						</c:if>
						</c:forEach>
						</tbody>
				  </table>
				  </c:if>
			    </div>
				
				<table border="0" cellspacing="0" cellpadding="0" align="center" class="table-0">
				    <tr>
	 					<td class="InfoTitleDivider"></td>
	 				</tr>
				</table>
				
				<table border="0" cellspacing="0" cellpadding="0" align="center" class="table-a2 BillElseInfo">
					<tr>
						<th>业务来源：</th>
				    	<td>${record.businessBill.introducerName}</td>
						<th>安装要求：</th>
				      	<td>${record.businessBill.setupRequire}</td>
						<th>合计金额：</th>
				      	<td >${record.businessBill.favCost+record.businessBill.cost}</td>
					</tr>
					<tr>
						<th>部门：</th>
				      	<td >${record.departmentName}</th>
						<th>提货要求：</th>
				      	<td >${record.businessBill.ladingRequire}</td>
						<th>优惠金额：</th>
				     	<td >${record.businessBill.favCost}</td>
					</tr>
					<tr>
						<th>业务员：</td>
				      	<td >${record.businessBill.managerName}</td>
						<th>交货日期：</th>
				    	<td ><c:if test="${record.businessBill.deliverDate!=null}"><fmt:formatDate value="${record.businessBill.deliverDate}" pattern="yyyy-MM-dd HH:mm"/></c:if></td>
						<th>折后金额：</td>
				     	<td>${record.businessBill.cost}</td>
					</tr>
					<tr>
						<th>跟单员：</td>
				      	<td >${record.businessBill.followerNameStr}</td>
				      	<th>送货地址：</th>
				    	<td >${record.businessBill.address}</td>
				    	<th>预付款：</th>
				      	<td >${record.businessBill.imprest}</td>
				    </tr>
					<tr>
						<td colspan="4" style="text-align:center"><div class="InfoDetailDivider"></div></td>
						<th>付款方式：</th>
				      	<td >${record.payModeName}</td>
					</tr>
					<tr>
						<th>设计类型：</th>
				      	<td >
				      		<c:if test="${record.businessBill.designType=='SELF'}">公司设计</c:if>
				      		<c:if test="${record.businessBill.designType=='CLIENT'}">客户来稿</c:if>
				      	</th>
				      	<th>摘要：</th>
				      	<td >${record.businessBill.content}</td>
				      	<th>收款账户：</th>
				      	<td >${record.bankAccountName}</td>
				    </tr>
					<tr>
				    	<th>设计员：</td>
				      	<td >${record.businessBill.designerNameStr}</td>
						<th>备注：</th>
				      	<td >${record.businessBill.mark}</td>
						<th>结账日期：</th>
				    	<td ><c:if test="${record.businessBill.checkDate!=null}"><fmt:formatDate value="${record.businessBill.checkDate}" pattern="yyyy-MM-dd"/></c:if></td>
				    </tr>
				</table>

			<c:if test="${fn:length(record.accessories)>0}">
			
			<table border="0" cellspacing="0" cellpadding="0" align="center" class="table-0">
			    <tr>
 					<td class="InfoTitleDivider"></td>
 				</tr>
			</table>
			
			<div class="table-list">	
			<table border="0" cellspacing="0" cellpadding="0" align="center" width="98%" >
				<tr>
					<th width="18%">文件</th>
					<th width="20%">资料路径</th>
					<th width="18%">文件说明</th>
					<th width="14%">工作中心</th>
					<th width="6%">类型</th>
					<th width="8%">上传人</th>
					<th width="12%">上传时间</th>
					<th width="4%">操作</td>
				</tr>
				<c:forEach var="item" items="${record.accessories}" varStatus="i">
				<tr>
					<td >
						<c:if test="${item.fileName!=null && item.fileName!=''}"><a href="${item.fileName}" target="_blank">${item.sourceName}</a></c:if>
						<c:if test="${item.fileName==null || item.fileName==''}">${item.sourceName}</c:if>
					</td>
					<td >${item.customPath}</td>
					<td >${item.mark}</td>
					<td>
						<input class='TextBox readonly' readonly="true" type="text" style="width:68px" id="acc_wc_name_${i.index}" name="acc_wc_name_${i.index}" value='<commonTag:showSimpleObjectName list="${workCenterList}" objectId="${item.extId}" />'>
						<img src="/images/icon_add.gif" style="cursor:pointer;" onClick="selectWc('acc_wc_id_${i.index}','acc_wc_name_${i.index}');">
						<img src="/images/icon_del.gif" style="cursor:pointer;" onClick="doClear('acc_wc_id_${i.index}','acc_wc_name_${i.index}');">
						<input type="hidden" id="acc_wc_id_${i.index}" name="acc_wc_id_${i.index}" value="${item.extId}">
						<input type="hidden" id="acc_id_${i.index}" name="acc_id_${i.index}" value="${item.id}">
					</td>
					<td >
						<select name="acc_type_${i.index}" id="acc_type_${i.index}">
							<option value=""></option>
							<option value="DESIGN" <c:if test="${item.accType=='DESIGN'}">selected="true"</c:if>>自制</option>
							<option value="COOPER" <c:if test="${item.accType=='COOPER'}">selected="true"</c:if>>外协</option>
							<option value="CONTRACT" <c:if test="${item.accType=='CONTRACT'}">selected="true"</c:if>>合同</option>
						</select>
					</td>
					<td >${item.createrName}</td>
					<td ><fmt:formatDate value="${item.createTime}" pattern="yyyy-MM-dd HH:mm"/></td>
					<td >
						<c:if test="${item.fileName!=null && item.fileName!=''}"><a href="javascript:doDownload('${item.id}','${item.fileName}','${item.sourceName}');">下载</a></c:if>
						<c:if test="${item.fileName==null || item.fileName==''}">下载</c:if>
					</td>
				</tr>
				</c:forEach>
			</table>
			</div>
			</c:if>

			<div class="blank12">&nbsp;</div>
			<p class="give">
				<span>开单人：${record.businessBill.createrName} <c:if test="${record.businessBill.createTime!=null}"><fmt:formatDate value="${record.businessBill.createTime}" pattern="yyyy-MM-dd HH:mm"/></c:if></span>
				<span>审核人：<c:if test="${record.businessBillExt.examinerId!=0}">${record.businessBillExt.examinerName} <c:if test="${record.businessBillExt.examineTime!=null}"><fmt:formatDate value="${record.businessBillExt.examineTime}" pattern="yyyy-MM-dd HH:mm"/></c:if></c:if></span>
				<span>结清：${record.businessBillExt.closerName} <fmt:formatDate value="${record.businessBillExt.closeTime}" pattern="yyyy-MM-dd HH:mm"/></span>
				<span>最后打印：<c:if test="${record.businessBillExt.lastPrinter!=null && record.businessBillExt.lastPrinter!=''}">${record.businessBillExt.lastPrinter} / 已打印${record.businessBillExt.printNum}次</c:if></span>
				<span>修改人：<c:if test="${record.businessBill.modifierId!=0}">${record.businessBill.modifierName} <fmt:formatDate value="${record.businessBill.modifyTime}" pattern="yyyy-MM-dd HH:mm"/></c:if></span>
				<span>单据帐套：${record.tallySetName}</span>
			</p>
		</div>
  	</div>
  </div>
	<div class="modal-buttom">	
		<c:if test="${record.businessBillExt.examined=='N' && record.businessBillExt.closed=='N'}">
			<input type="button"  class="buttom-a" value=" 审核通过" onClick="doExamine();">
			<input type="button"  class="buttom-a" value=" 退回通知 " onClick="doNewMessage(${record.businessBill.id},'${record.businessBill.billCode}','${record.businessBill.createrId}','${record.businessBill.createrName}');">
		</c:if>
		<c:if test="${(currentUser.user.userType==1 || fn:indexOf(currentUser.privs,';BUSI_MODI;')!=-1) && record.businessBillExt.closed=='N'}">
			<input type="button"  class="buttom-a" value=" 编 辑 " onClick="doEdit('${record.businessBill.id}');">
		</c:if>
		<input type="button"  class="buttom-a" value=" 退 出 " onClick="doCancel();">
		<form method="post" name="frm" id="frm" action="BusinessBillExamine.ihtm">
			<input type="hidden" name="flag" id="flag" value="SINGLE_EXA">
			<input type="hidden" name="bill_id" id="bill_id" value="${record.businessBill.id}">
			<input type="hidden" name="wc_id_str" id="wc_id_str" value="">
			<input type="hidden" name="cooper_str" id="cooper_str" value="">
			<input type="hidden" name="acc_wc_id_str" id="acc_wc_id_str" value="">
			<input type="hidden" name="acc_type_str" id="acc_type_str" value="">
		</form>
	</div>
</div>
</body>
</html>
